package com.project.app.server.estates;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.server.domain.estates.TPayRecord;
import com.project.server.service.companies.ITCompanyService;
import com.project.server.service.estates.ITPayRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/app/server/payRecord")
public class ATPayRecordController extends BaseController {

    @Resource
    private ITPayRecordService tPayRecordService;

    @Resource
    private ITCompanyService companyService;

    /**
     * 查询缴费记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TPayRecord tPayRecord) {
        startPage();
        List<TPayRecord> list = tPayRecordService.selectTPayRecordList(tPayRecord);
        return getDataTable(list);
    }

    /**
     * 获取缴费记录详细信息
     */
    @GetMapping(value = {"/{userId}"})
    public AjaxResult getInfo(TPayRecord tPayRecord) {
        return AjaxResult.success(tPayRecordService.selectTPayRecordByUserId(tPayRecord));
    }

    /**
     * 新增缴费记录
     */
    @Log(title = "缴费记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TPayRecord tPayRecord) {
        return toAjax(tPayRecordService.insertTPayRecord(tPayRecord));
    }

    /**
     * 修改缴费记录
     */
    @Log(title = "缴费记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TPayRecord tPayRecord) {
        return toAjax(tPayRecordService.updateTPayRecord(tPayRecord));
    }

    /**
     * 删除缴费记录
     */
    @Log(title = "缴费记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{payIds}")
    public AjaxResult remove(@PathVariable Long[] payIds) {
        return toAjax(tPayRecordService.deleteTPayRecordByIds(payIds));
    }
}
